import {LitElement, html} from 'lit';

function truncate(text = '', stop, clamp) {
  return text.slice(0, stop) + (stop < text.length ? clamp || '...' : '')
}

class ZwTruncate extends LitElement {
  constructor() {
    super();
    this.num = 6;
  }
  render() {
    let computedText = truncate(this.text, this.num, '...')
    return html`<div id="main" part="main">${computedText}</div>`
  }
}

ZwTruncate.properties = {
  num: {type: Number},
  text: {type: String}
}

customElements.define('zw-truncate', ZwTruncate)
